var id = GetQueryString("id");
		var vm = new Vue({
			el: '#app',
			data: {
				enums: {
					userLevel: {
						"1": "注册用户",
						"2": "普通推广员",
						"3": "黄金推广员",
						"4": "铂金推广员"
					},
					show: {
						taskAmount: true,
						assureAmount: true
					}
				},
				user: {
					userVip: 0,
					assureAmount: 0,
					taskAmount: 0,
					password: ''
				},
			},
			methods: {
				/**
				 * 用户信息
				 */
				getUser: function() {
					$.get(baseURL + 'user/info/' + id, function(data) {
						vm.user = data.user;
						vm.user.password = "";
						vm.$nextTick(function() {
							// 初始化图片插件
							initDropify();
						}
					)}, 'JSON');
				},
				saveOrUpdate: function() {
					var url = vm.user.id == null ? "user/save" : "user/update";
					$.loadAjax({
						type: "POST",
						url: baseURL + url,
						contentType: "application/json",
						data: JSON.stringify(vm.user),
						success: function(r) {
							if (r.code === 0) {
								layer.alert('提交成功', function(index) {
									backToTable();
									layer.close(index);
								});
							} else {
								layer.alert(r.msg);
							}
						}
					});
				}
			},
			mounted() {
				if (id != null && id != '') {
					this.getUser();
					this.enums.show.taskAmount = false;
					this.enums.show.assureAmount = false;
				} else {
					initDropify();
				}
			}
		})
		
		function initDropify() {

			// 文件上传配置
			var drEvent = $('.dropify').dropify({
				messages: {
					'default': '点击上传照片',
					'replace': '',
					'remove': '移除',
					'error': '对不起，你上传的文件太大了',
				}
			});
			drEvent.on('dropify.error.fileSize', function(event, element) {
				layer.msg('图片大小不超过1M!');
			});
			drEvent.on('dropify.error.imageFormat', function(event, element) {
				alert('仅支持jpg,png,jpeg,gif类型图片!');
			});
			drEvent.on('dropify.afterClear', function(event, element) {
				layer.msg('图片移除成功');
			});
		}

		// 图片上传
		$('form').on("change", ".dropify", function(e) {
			
			var i = layer.load(1);
			var clazz = ('.' + $(this).attr("id")).replace('jUploadFile', '');
			$.ajaxFileUpload({
				type: "POST",
				url: baseURL + "/fileUpload",
				data: {
					'token': token
				}, //要传到后台的参数，没有可以不写  
				secureuri: false, //是否启用安全提交，默认为false  
				fileElementId: $(this).attr("id"), //文件选择框  
				dataType: 'json', //服务器返回的格式  
				async: false,
				success: function(data) {
					layer.close(i);
					if (data.code === 0) {
						layer.msg('上传成功！');
						$(clazz).val(data.url);
						vm.user.avatar = data.url;
					} else {
						layer.alert(data.msg);
					}
				},
				error: function(data, status, e) {
					layer.close(i);
					layer.msg('上传失败！');
				}
			});
		});

		//表单验证
		$(function() {

			$("#editForm").validate({
				rules: {
					nickName: "required",
					avatar: "required",
					taskAmount: {
						required: true,
						digits: true,
						min: 0
					},
					assureAmount: {
						required: true,
						digits: true,
						min: 0
					},
					phone: "required",
					password: "required",
					userLevel: "required",
					userVip: "required"
				},
				messages: {
					nickName: "昵称不能为空",
					avatar: "头像不能为空",
					taskAmount: {
						required: "任务余额不能为空",
						digits: "任务余额必须是整数",
						min: "任务余额不能是负数"
					},
					assureAmount:{
						required: "保证金不能为空",
						digits: "保证金必须是整数",
						min: "保证金不能是负数"
					},
					phone: "账号不能为空",
					password: "密码不能为空",
					userLevel: "用户等级不能为空",
					userVip: "是否为会员"
				},
				submitHandler: function(form) { //验证通过后的执行方法

					//当前的form通过ajax方式提交
					vm.saveOrUpdate();
				},
				/* 重写错误显示消息方法,以tips方式弹出错误消息 */
				showErrors: function(errorMap, errorList) {
					var msg = "";
					$.each(errorList, function(i, v) {
						msg = (v.message + "\r\n");
						if (msg != "") layer.tips(msg, "#" + v.element.id, {
							tips: 2,
							tipsMore: true
						});
					});
				},
				/* 提示失去焦点时不验证 */
				onfocusout: false
			});
		});
